package BIO.test01;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 目标，客户端发送消息，服务端能够接收消息
 */
public class Server {
    public static void main(String[] args) {
        System.out.println("=====服务端启动======");
        try {
            //1.定义serverSocket对象进行服务端的端口注册
            ServerSocket ss = new ServerSocket(9999);
            //2.监听客户端Socket连接请求
            Socket socket = ss.accept();
            //3.从socket管道中得到字节输入流对象
            InputStream inputStream = socket.getInputStream();
            //4.把字节输入流包装成缓冲字符输入流
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            String msg;
            if ((msg = br.readLine()) != null){
                System.out.println("服务端接收到:"+msg);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
